// pages/auth/index.js


import {
  request
} from "../../request/index"
import regeneratorRuntime from "../../lib/runtime/runtime.js";
import {
  login
} from "../../request/asyncWx.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  // 获取用户信息
  async handleGetUserInfo(e) {
  try {
      // 1 获取用户信息
      const {
        encryptedData,
        rawData,
        iv,
        signature
      } = e.detail;
      // 2 获取小程序登录后的值
      const {
        code
      } = await login();
      const loginParams = {
        encryptedData,
        rawData,
        iv,
        signature,
        code
      };
      // 3 发送请求 获取用户的token
      const {
        token
      } = await request({
        url: '/users/wxlogin',
        data: loginParams,
        method: "post"
      })
      // 4 把token存入缓存中 同时跳转回上一个页面
      wx.setStorageSync('token', token);
      wx.wx.navigateBack({
        delta: 1,
      })
  } catch (error) {
    console.log(error)
  }
  }

})